import { customTable } from '@/components/ProTable/interface';
import { ProTableValue } from '@/interface/public';
import dayjs from 'dayjs';
import { useFormAddCourse } from './use-formAddCourse';
import { DrawerDataProps } from '@/hooks/table/use-drawer';
/**
 * @name 系统全局配置
 */
export function useDataCourse(detailRef: ProTableValue, drawerData: DrawerDataProps['drawerData']) {
  const { formAddCourse } = useFormAddCourse(detailRef);
  let dataCourse = reactive<customTable>({
    initParam: {
      modelId: ''
    },
    // 表格配置项
    columns: [
      { prop: 'operation', label: 'operation', fixed: 'left', width: 140 },
      {
        label: '课程描述',
        prop: 'classMark'
      },
      {
        label: '排序',
        prop: 'showOrder'
      },
      {
        label: '备注',
        prop: 'remark'
      }
    ],
    headButtonList: [
      {
        label: 'add',
        type: 'primary',
        icon: 'Plus',
        // permissionCode: "dictionary:save",
        methods: async () => {
          if (!drawerData.row.id) {
            elMessage('请选择模板', 'warning');
            return;
          }
          formOpen(formAddCourse, '新增课程', {
            modelId: drawerData.row.id
          });
        }
      }
    ],
    rowButtonList: [
      {
        label: 'edit',
        type: 'primary',
        // permissionCode: "system:save",
        methods: (row: any) => {
          formOpen(formAddCourse, '编辑课程', row);
        },
        attrs: {
          link: true
        }
      },
      {
        label: '删除',
        type: 'danger',
        methods: row => {
          const params = { id: row.id, modelId: row.modelId };
          useHandleData(modelRemoveClassMark, params, `删除${row.classMark}`, detailRef.value?.getTableList);
        },
        attrs: {
          link: true
        }
      }
    ]
  });

  return { dataCourse, formAddCourse };
}
